package com.tanhua.server.controller;

import com.tanhua.server.service.IMService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class IMController {

    @Autowired(required = false)
    private IMService imService;

    /**
     *接口名称：根据环信id查询用户信息\
     * 接口路径：GET/messages/userinfo
     */
    @GetMapping("/userinfo")
    public ResponseEntity<Object> getHuanxinUserInfo(Long huanxinId){
        return imService.getHuanxinUserInfo(huanxinId);
    }


    /**
     *接口名称：联系人添加
     * 接口路径：POST/messages/contacts
     */
    @PostMapping("/contacts")
    public ResponseEntity<Object> addContact(@RequestBody Map<String,Integer> paramMap){
        Integer friendUserId = paramMap.get("userId");
        return imService.addContact(friendUserId);
    }


    /**
     *接口名称：联系人列表
     * 接口路径：GET/messages/contacts
     */
    @GetMapping("/contacts")
    public ResponseEntity<Object> queryContractList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize, String keyword) {
        if(page==2){
            page=1;
        }
        return imService.queryContractList(page,pagesize,keyword);
    }
}
